<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card" style="height: 614px">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="text-center">
              <userAvatar :user="user"/>
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user"/>
                用户名称
                <div class="pull-right">{{ user.userName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone"/>
                手机号码
                <div class="pull-right">{{ user.phonenumber }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="tree"/>
                所属部门
                <div class="pull-right" v-if="user.dept">{{ user.ancestorNames }}</div>
              </li>
              <li class="list-group-item" style="height: 80px">
                <svg-icon icon-class="peoples"/>
                所属角色
                <div style="margin-top: 10px" class="pull-right">{{ roleGroup }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date"/>
                创建日期
                <div class="pull-right">{{ user.createTime }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="wechat_color"/>
                微信
                <div v-if="user.isBandChat >0" class="pull-right">
                  <el-button type="text" style="color: red;" :loading="bindBtnLoading"
                             @click="chatUnBandHandler(user.userId)">解绑
                  </el-button>
                </div>
                <div v-if="user.isBandChat <1" class="pull-right" style="color: red;">未绑定</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card style="height: 614px" v-show="totals > 0">
          <div slot="header" class="clearfix">
            <span>积分明细</span>
          </div>
          <el-table v-loading="loading" :data="scoreList">
            <el-table-column align="center" label="时间" property="examineTime" width="250"/>
            <el-table-column property="score" label="积分" width="150" align="center"/>
            <el-table-column property="honorScore" label="荣誉值" width="150" align="center"/>
            <el-table-column property="examineTypeAppend" label="内容" align="center" show-overflow-tooltip/>
          </el-table>
          <pagination
            v-show="totals>0"
            :total="totals"
            :page.sync="scoreQueryParams.pageNum"
            :limit.sync="scoreQueryParams.pageSize"
            @pagination="getExamineUserScore"
          />
        </el-card>
        <div
          v-show="totals == 0"
          :style="style">
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userAvatar from "@/views/system/user/profile/userAvatar";
import userInfo from "@/views/system/user/profile/userInfo";
import resetPwd from "@/views/system/user/profile/resetPwd";
import {getUserProfile, unBindOpenid} from "@/api/system/user";
import {listExamineUser, myScoreList} from "@/api/examine/user/api";

export default {
  name: "Profile",
  components: {userAvatar, userInfo, resetPwd},
  data() {
    return {
      style: {
        height: '760px',
        backgroundImage: `url(${require("@/assets/images/scoreBg.jpg")})`,
        borderRadius: '5px',
        backgroundColor: 'rgba(103,204,255, 0.1)',
        backgroundSize: 'contain',
        backgroundPosition: 'center',
        backgroundRepeat: 'no-repeat'
      },
      totals: 0,
      scoreQueryParams: {
        pageNum: 1,
        pageSize: 10,
        isSubmitted: 1,
        examineStatus: 2,
        orderByColumn: 'a.examine_time',
        isAsc: 'desc'
      },
      user: {},
      roleGroup: {},
      postGroup: {},
      scoreList: [],
      activeTab: "userinfo",
      loading: false,
      bindBtnLoading: false
    };
  },
  created() {
    this.getUser();
    this.getExamineUserScore();
  },
  methods: {
    getUser() {
      getUserProfile().then(response => {
        if (response.data.ancestorNames) {
          if (response.data.ancestorNames !== '昌泰集团') {
            response.data.ancestorNames = response.data.ancestorNames.substring(5, response.data.ancestorNames.length)
          }
        }
        this.user = response.data;
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
      });
    },
    getExamineUserScore() {
      this.loading = true
      myScoreList(this.scoreQueryParams).then(response => {
        this.dialogTableVisible = true
        this.scoreList = response.rows
        this.totals = response.total
        this.loading = false
      }).finally(() => {
        this.loading = false
      })
    },
    chatUnBandHandler(userId) {
      this.$confirm('确认解绑微信?', '提示', {type: 'warning'}).then(() => {
        this.bindBtnLoading = true
        unBindOpenid(userId).then(() => {
          this.getUser();
          this.$modal.msgSuccess("解绑成功");
        }).finally(() => {
          this.bindBtnLoading = false
        })
      })
    }
  }
};
</script>
